/**************************************************************************
* DS_WILDCARD.H                                                12.03.2007 *
*                                                                         *
* .                                                                       *
**************************************************************************/
#ifndef _DS_WILDCARD_H_
#define _DS_WILDCARD_H_

#pragma once

#include "ds\ds_string.h"
#include "ds\ds_vector.h"

namespace ds {

class WILDCARD {
public:
   WILDCARD                (void);
   WILDCARD                (const dsSTRING & pattern, bool caseSensitive = true) { Init(pattern, caseSensitive); }

   // example: part1*part2|part3|*part4~part5*
   // | means or
   // ~ means not
   void                    Init                    (const dsSTRING & pattern, bool caseSensitive = true);
   void                    Term                    (void);

   bool                    Match                   (const dsSTRING & text) const;

public:
   typedef dsVECTOR<dsSTRING>     STRING_ARRAY;
   typedef dsVECTOR<STRING_ARRAY> STRING_TABLE;

private:
   bool                    Match                   (const dsSTRING & text, const STRING_ARRAY & mask) const;

private:
   bool                    caseSensitive;

   STRING_TABLE            direct;
   STRING_TABLE            revert;
};

// support wildcards like "prefix*middle*suffix"
class SIMPLE_WILDCARD {
public:
   SIMPLE_WILDCARD(void)                  {}
   SIMPLE_WILDCARD(const dsSTRING & rule) { Init(rule.CStr()); }
   SIMPLE_WILDCARD(const char * rule)     { Init(rule); }

   void                 Init              (const dsSTRING & rule) { Init(rule.CStr()); }
   void                 Init              (const char * rule);
   bool                 Match             (const dsSTRING & text) const { return Match(text.CStr()); }
   bool                 Match             (const char * text) const;

public:
   dsSTRING             prefix;
   dsSTRING             middle;
   dsSTRING             suffix;
};

} // namespace ds

#endif // _DS_WILDCARD_H_
